package com.hskn.hss.module.operatedauthor.controller;


import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.hskn.hss.core.annotation.SysLog;
import com.hskn.hss.core.enums.BusinessType;
import com.hskn.hss.entity.AjaxResult;
import com.hskn.hss.exception.HssException;
import com.hskn.hss.module.insuranceCfg.entity.TlInsuranceCfg;
import com.hskn.hss.module.operatedauthor.entity.SysRoleMenu;
import com.hskn.hss.module.operatedauthor.mapper.SysRoleMenuMapper;
import com.hskn.hss.module.operatedauthor.service.ISysRoleMenuService;
import com.hskn.hss.module.tlopetation.mapper.TlOperationMapper;
import com.hskn.hss.utils.Tools;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author hskn
 * @since 2021-05-04
 */
@Slf4j
@RestController
@RequestMapping("/hss/sysrolemenu")
public class SysRoleMenuController {
    @Autowired
    private ISysRoleMenuService sysRoleMenuService;

    @SysLog(businessType = BusinessType.INSERT, tableName = "sys_role_menu", bean = SysRoleMenu.class, beanMapper = SysRoleMenuMapper.class, names = "roleid, menuid")
    @RequestMapping(value = "insertRoleMenu", method = RequestMethod.POST)
    public AjaxResult<Object> insertRoleMenu(HttpServletRequest request) {
        try {
            JSONObject params = JSON.parseObject(Tools.getBody(request));
            return sysRoleMenuService.insert(params);
        } catch (HssException e) {
            e.printStackTrace();
            log.error("报错ERROR", e);
            return AjaxResult.fail("操作失败，请稍后再试");
        }
    }

    @SysLog(businessType = BusinessType.UPDATE, tableName = "sys_role_menu", idKey = "id", bean = SysRoleMenu.class, beanMapper = SysRoleMenuMapper.class, names = "roleid, menuid")
    @RequestMapping(value = "updateRoleMenu", method = RequestMethod.POST)
    public AjaxResult<Object> updateRoleMenu(HttpServletRequest request) {
        try {
            JSONObject params = JSON.parseObject(Tools.getBody(request));
            return sysRoleMenuService.update(params);
        } catch (HssException e) {
            e.printStackTrace();
            log.error("报错ERROR", e);
            return AjaxResult.fail("操作失败，请稍后再试");
        }
    }

    @SysLog(businessType = BusinessType.DELETE, tableName = "sys_role_menu", idKey = "id", bean = SysRoleMenu.class, beanMapper = SysRoleMenuMapper.class, names = "roleid, menuid")
    @RequestMapping(value = "deleteRoleMenuById", method = RequestMethod.POST)
    public AjaxResult<Object> deleteRoleMenuById(HttpServletRequest request) {
        JSONObject params = JSON.parseObject(Tools.getBody(request));
        try {
            return sysRoleMenuService.deleteByid(params);
        } catch (HssException e) {
            e.printStackTrace();
            log.error("报错ERROR", e);
            return AjaxResult.fail("删除失败，请稍后再试");
        }
    }

    @RequestMapping(value = "getRoleMenuById", method = RequestMethod.POST)
    public AjaxResult<Object> getRoleMenuById(HttpServletRequest request) {
        JSONObject params = JSON.parseObject(Tools.getBody(request));
        SysRoleMenu sysRoleMenu = null;
        try {
            sysRoleMenu = sysRoleMenuService.getInfoById(params);
        } catch (HssException e) {
            e.printStackTrace();
            log.error("报错ERROR", e);
            return AjaxResult.fail("获取信息失败，请稍后再试");
        }
        return AjaxResult.success(sysRoleMenu);

    }

    @RequestMapping(value = "getRoleMenuList", method = RequestMethod.POST)
    public AjaxResult<Object> getRoleMenuList(HttpServletRequest request) {
        JSONObject params = JSON.parseObject(Tools.getBody(request));
        List<SysRoleMenu> RoleMenuList = null;
        try {
            RoleMenuList = sysRoleMenuService.getListByMap(params);
        } catch (HssException e) {
            e.printStackTrace();
            log.error("报错ERROR", e);
            return AjaxResult.fail("获取信息失败，请稍后再试");
        }
        return AjaxResult.success(RoleMenuList);
    }
}

